----------------------------------------------
-- Config
----------------------------------------------
-- Minimap
scale = 1                   -- Scale
position = "TOPLEFT"        -- Initial Position

-- Borders
borders = true              -- Enables or disables the white border on the minimap. True/False
bordersize = 1              -- Size of Border

whiteborder = false         -- Enables or disables the white outline on the Minimap. True/False

color =  { r=.6, g=.6, b=.6}-- Border Outline Color
color2 = { r=0, g=0, b=0}   -- Border Color

-- Quest 
qparent = Minimap           -- Use "Minimap" or "UIParent". Defines what frame the anchor position is relative to.
qanchor = "BOTTOMRIGHT"     -- Where to anchor on the qparent ^
qposition_x = 10             -- X Offset
qposition_y = -80           -- Y Offset
qheight = 500               -- Determines the height of the quest tracker

----------------------------------------------
-- Config End
----------------------------------------------
local backdrop = {bgFile = 'Interface\\Buttons\\WHITE8x8', edgeFile = 'Interface\\Addons\\WHITE8x8', edgeSize = bordersize, insets = {left = -bordersize, right = -bordersize, top = -bordersize, bottom = -bordersize}}
local font = "FONTS\\FRIZQT__.ttf"
local mailicon = "Interface\\AddOns\\bMinimap\\mail"

Minimap:SetMaskTexture('Interface\\Buttons\\WHITE8x8')
Minimap:SetScale(scale)
Minimap:SetFrameStrata("BACKGROUND")
Minimap:ClearAllPoints()
Minimap:SetPoint(position, UIParent, 20, -20)

Minimap:SetMovable(true)
Minimap:EnableMouse(true)
Minimap:RegisterForDrag("LeftButton","RightButton")
Minimap:SetScript("OnDragStart", function(self) if IsAltKeyDown() and IsShiftKeyDown() then self:StartMoving() end end)
Minimap:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
Minimap:SetUserPlaced(true)
SlashCmdList["RESETMINIMAP"] = function() 
    Minimap:SetUserPlaced(false)
    ReloadUI()
end
SLASH_RESETMINIMAP1 = "/bminimapreset"

----------------------------------------------
-- Border
----------------------------------------------
if (borders == true) then
    Minimap:SetBackdrop(backdrop)
    Minimap:SetBackdropBorderColor(color2.r,color2.g,color2.b)  
    if (whiteborder == true) then
        Minimap:SetBackdropBorderColor(color.r,color.g,color.b)
    else
        Minimap:SetBackdropBorderColor(0,0,0,0)
    end
end

----------------------------------
-- Hide Shit
----------------------------------
MinimapBorder:Hide()
MinimapBorderTop:Hide()
MinimapZoomIn:Hide()
MinimapZoomOut:Hide()
MiniMapVoiceChatFrame:Hide()
GameTimeFrame:Hide()
MinimapZoneTextButton:Hide()
MiniMapTracking:Hide()
MiniMapMailFrame:ClearAllPoints()
MiniMapMailFrame:SetPoint("TOPRIGHT", Minimap, 3, 4)
MiniMapMailIcon:SetTexture(mailicon)
MiniMapMailBorder:Hide()
MinimapNorthTag:SetAlpha(0)
MiniMapInstanceDifficulty:SetAlpha(0)
GuildInstanceDifficulty:SetAlpha(0)

----------------------------------
-- Move Shit
----------------------------------
WatchFrame:ClearAllPoints()	
WatchFrame.ClearAllPoints = function() end
WatchFrame:SetPoint("TOPRIGHT", qparent, qanchor, qposition_x, qposition_y)
WatchFrame.SetPoint = function() end
WatchFrame:SetClampedToScreen(true)
WatchFrame:SetHeight(qheight)

MiniMapBattlefieldFrame:ClearAllPoints()
MiniMapBattlefieldFrame:SetPoint("BOTTOMRIGHT", Minimap, 3, 0)
MiniMapBattlefieldFrame:SetFrameLevel(3)
MiniMapBattlefieldBorder:Hide()
MiniMapWorldMapButton:Hide()

MiniMapInstanceDifficulty:ClearAllPoints()
MiniMapInstanceDifficulty:SetParent(Minimap)
MiniMapInstanceDifficulty:SetPoint("TOPLEFT", Minimap, "TOPLEFT", 0, 0)
function UpdateLFG()
	MiniMapLFGFrame:ClearAllPoints()
	MiniMapLFGFrame:SetPoint("BOTTOMLEFT", Minimap, "BOTTOMLEFT", 2, 1)
    LFDSearchStatus:ClearAllPoints()
    LFDSearchStatus:SetPoint(position, MiniMapLFGFrame, position)
    LFDSearchStatus:SetClampedToScreen(true)
end
MiniMapLFGFrameBorder:SetAlpha(0)
DropDownList1:SetClampedToScreen(true)
hooksecurefunc("MiniMapLFG_UpdateIsShown", UpdateLFG)

----------------------------------
-- Time
----------------------------------
LoadAddOn('Blizzard_TimeManager')

local clockFrame, clockTime = TimeManagerClockButton:GetRegions()
clockFrame:Hide()
clockTime:Hide()
clockTime:SetFont(font, 14)
    if(CalendarGetNumPendingInvites() > 0) then
		clockTime:SetTextColor(0, 1, 0)
	else
		clockTime:SetTextColor(1, 1, 1)
    end
TimeManagerClockButton:SetPoint("CENTER", Minimap, "BOTTOM", -2, 10)
Minimap:SetScript("OnEnter", function()
    clockTime:Show()
    UIFrameFadeIn(clockTime, 0.2, 0, 1)
end)
Minimap:SetScript("OnLeave", function()
	clockTime:show()
    UIFrameFadeOut(clockTime, 0.2, 1, 0)
end)

TimeManagerClockButton:EnableMouse(false)


Minimap:EnableMouseWheel(true)
Minimap:SetScript('OnMouseWheel', function(self, delta)
    if delta > 0 then
        Minimap_ZoomIn()
    else
        Minimap_ZoomOut() 
    end
end)

Minimap:SetScript('OnMouseUp', function(self, button)
    if (button == 'RightButton') then
        ToggleDropDownMenu(1, nil, MiniMapTrackingDropDown, self, - (Minimap:GetWidth() * 0.7), -3)
    elseif (button == 'MiddleButton') then
        ToggleCalendar()
    else
        Minimap_OnClick(self)
    end
end)

function GetMinimapShape() return 'SQUARE' end